package edu.hwadee.serviceImpl;

import java.util.List;

import edu.hwadee.entity.Majorbusiness;
import edu.hwadee.service.MajorbusinessService;

public class MajorbusinessServiceImpl extends BasicServiceImpl implements MajorbusinessService {

	@Override
	public boolean save(Majorbusiness majorbusiness) {
		try {
			getMajorbusinessDAO().save(majorbusiness);
			return true;
		} catch (Exception e) {
			e.printStackTrace();
		}
		return false;
	}

	@Override
	public boolean delete(Majorbusiness majorbusiness) {
		try {
			getMajorbusinessDAO().delete(majorbusiness);
			return true;
		} catch (Exception e) {
			e.printStackTrace();
		}
		return false;
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<Majorbusiness> search(Majorbusiness majorbusiness) {
		try {
			return (List<Majorbusiness>)getMajorbusinessDAO().findByExample(majorbusiness);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return null;
	}

	@Override
	public Majorbusiness searchById(Integer majorbusinessId) {
		try {
			return getMajorbusinessDAO().findById(majorbusinessId);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return null;
	}

	@Override
	public boolean update(Majorbusiness majorbusiness) {
		try {
			if(searchById(majorbusiness.getMajorBusinessId()) != null) {
				getMajorbusinessDAO().merge(majorbusiness);
				return true;
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return false;
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<Majorbusiness> showAll() {
		try {
			return (List<Majorbusiness>)getMajorbusinessDAO().findAll();
		} catch (Exception e) {
			e.printStackTrace();
		}
		return null;
	}

}
